/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xuexiang.xuidemo.slice.imageview.preview.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

import com.xuexiang.xuidemo.ResourceTable;

/**
 * 图片预览
 *
 * @since 2021-04-08
 */
public class PreviewImageSlice extends AbilitySlice implements Component.ClickedListener {
    private Image mImageBack;
    private DirectionalLayout mRecycleLook,mGridLook;
    Intent intent;
    Operation operation;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_preview_image);
        initView();
        initClickedListener();
    }

    public void initView() {
        mImageBack = (Image) findComponentById(ResourceTable.Id_image_back);
        mRecycleLook = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_recycle_look);
        mGridLook = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_grid_look);
    }
    private void initClickedListener() {
        mImageBack.setClickedListener(this);
        mRecycleLook.setClickedListener(this);
        mGridLook.setClickedListener(this);
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                intent = new Intent();
                operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName("com.xuexiang.xuidemo.ability.ImageAbility")
                    .build();
                intent.setOperation(operation);
                startAbility(intent);
                setTransitionAnimation(0,0);
                break;
            case ResourceTable.Id_dl_recycle_look:
                intent = new Intent();
                operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName("com.xuexiang.xuidemo.slice.imageview.preview.PreviewRecycleViewAbility")
                    .build();
                intent.setOperation(operation);
                startAbility(intent);
                setTransitionAnimation(0,0);
                break;
            case ResourceTable.Id_dl_grid_look:
                intent = new Intent();
                operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName(getBundleName())
                    .withAbilityName("com.xuexiang.xuidemo.slice.imageview.preview.NineGridImageViewAbility")
                    .build();
                intent.setOperation(operation);
                startAbility(intent);
                setTransitionAnimation(0,0);
                break;
        }
    }
}
